/*
 * C/C++ Lessons Program
 * 
 * Copyright (c) 2012 Ken Zhang (cpp.china@hotmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 */


#include <iostream>

using namespace std;

/* If Statements */
void test_age(int age)
{
	cout << "Your age is " << age << ", you are ";

	if (age > 60) {
		cout << "an old people";
	}
	else if (age > 30) {
		cout << "middle aged";
	}
	else if (age > 15) {
		cout << "a young people";
	}
	else if (age > 5) {
		cout << "a child";
	}
	else {
		cout << "a baby";
	}

	cout << endl;
}

/* For Statements */
int sum(int first, int last)
{
	int sum = 0;
	int i;

	for (i = first; i <= last; i++) {
		sum += i;
	}

	return sum;
}

void test_sum()
{
	cout << "1+2+...+99+100 = " << sum(1, 100) << endl;
}

/* While Statements */
void test_while()
{
	int ret = 1;
	int i = 4;

	while (i >= 1) {
		ret *= i;
		--i;
	}

	cout << "1*2*3*4 = " << ret << endl;
}

/* Switch Statements */
void test_switch()
{
	enum EDirection { North, East, South, West };
	EDirection direction = South;

	cout << "Your direction is: ";

	switch (direction) {
	case North:
		cout << "north";
		break;
	case East:
		cout << "east";
		break;
	case South:
		cout << "south";
		break;
	default:
		cout << "west";
		break;
	}

	cout << endl;
}

int main()
{
	test_age(25);
	test_sum();
	test_while();
	test_switch();

	return 0;
}

